package com.irisking.ikaisdk.handler;

import com.irisking.ikaisdk.AbstractServerSDK;
import com.irisking.ikaisdk.dataStruct.BasicJsonRec;
import com.irisking.ikaisdk.dataStruct.BasicJsonResp;
import com.irisking.ikaisdk.common.JacksonUtil;

public abstract class BaseHandler implements INetOpcode {
    public AbstractServerSDK abstractServerSDK;

    public BaseHandler(AbstractServerSDK serverSDK){
        this.abstractServerSDK = serverSDK;
    }

    public BasicJsonRec deserialize(String json) {
        return  JacksonUtil.getInstance().fromJson(json, BasicJsonRec.class);
    }

    /**
     * 提供给上层应用的回调， 上层引用手动确认消息接收成功
     */
    protected AckCallBack callBack = new AckCallBack() {

        @Override
        public void call(String sn, long timeStamp, int code, String message ) {
            BasicJsonResp resp = new BasicJsonResp();
            resp.setOperation(OperationCode.KEEP_ALIVE);
            resp.setTimestamp(timeStamp);
            resp.setCode(code);
            resp.setMessage(message);
            resp.setSn(sn);

            abstractServerSDK.SendAckDataToDevSn(resp, sn);
        }
    };
}
